<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>限时秒杀</title>
    <style>
        .mid{
            width: 620px;
            margin: 50px auto;
        }
        .mid .first div{
            font-size: large;
            line-height: 50px;
            width: 80px;
            height: 50px;
            float:left;
        }
        .first{
            position: relative;
            left: 160px;
        }
        a{
            position: relative;
            right: 250px;
            float: right;
            font-size: large;
            text-decoration: none;
        }
        body{
            background-color: #F3EFE0;
        }
        .bot{
            color: #918E84;
            font-family:Arial, Helvetica, sans-serif;
            font-size: 24px;
            position: relative;
            right: 250px;
            float: right;
        }
    </style>
</head>
<body>
    <div class="mid">
        <img src="2.jpg" alt="">
        <h2 style="text-align: center;">距离春节时间:</h2>
        <div  class="first">
            <div id="d"></div>
            <div id="h"></div>
            <div id="m"></div>
            <div id="s"></div>
        </div>
    </div>
    <br><br><br>
    <a href="../章节目录/第六章.html">返回上一页</a>
    <div class="bot"><br>
        <h3>Please appreciate((●'◡'●))......</h3>
    </div>
    <script>
        //设置秒杀结束时间
        var endTime = new Date('2020-01-25 00:00'), endSeconds = endTime.getTime();
        //定义变量保存剩余时间
        var d = h = m = s = 0;
        //设置定时器, 实现现实秒杀效果,每过1s,执行一次seckill函数
        var id = setInterval(seckill, 1000);
        function seckill(){
            //获取现在的时间对象
            var nowTime = new Date();
            //获取距离活动开始剩余的秒数
            var remaining = parseInt((endSeconds-nowTime.getTime())/1000);
            if(remaining > 0){
                //获取天数
                d = parseInt(remaining/86400);
                //获取小时数
                h = parseInt((remaining/3600)%24);
                //获取分钟
                m = parseInt((remaining/60)%60);
                //获取秒数
                s = parseInt(remaining%60);
                //格式化输出天数,小时,分钟,秒
                d = d < 10 ? '0' + d : d;
                h = h < 10 ? '0' + h : h;
                m = m < 10 ? '0' + m : m;
                s = s < 10 ? '0' + s : s;
            }else{
                //取消设置的定时器
                clearInterval(id);
                //所有距离活动开始的天数,小时,分钟,秒归为0
                d = h = m = s = '00';
            }
            //将信息显示到网页中
            document.getElementById('d').innerHTML = d + '天';
            document.getElementById('h').innerHTML = h + '时';
            document.getElementById('m').innerHTML = m + '分';
            document.getElementById('s').innerHTML = s + '秒';
        }
    </script>
</body>
</html>